<template>
  <div class="index-lists">
    <el-card class="!border-none" shadow="never">
      <el-form
        ref="formRef"
        class="mb-[-16px]"
        :model="queryParams"
        :inline="true"
      >
        <el-form-item label="审核状态" prop="name">
          <el-select
            v-model="queryParams.reviewStatus"
            filterable
            placeholder="请选择服务名称"
          >
            <el-option label="待审核" :value="0"></el-option>
            <el-option label="通过" :value="1"></el-option>
            <el-option label="拒绝" :value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="订单号" prop="orderSn">
          <el-input v-model="queryParams.orderSn" placeholder="请选择服务名称">
          </el-input>
        </el-form-item>
        <el-form-item label="退货订单" prop="refundSn">
          <el-input v-model="queryParams.refundSn" placeholder="请选择服务名称">
          </el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="resetPage">查询</el-button>
          <el-button @click="resetParams">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="!border-none mt-4" shadow="never">
      <el-table
        class="mt-4"
        size="large"
        v-loading="pager.loading"
        :data="pager.lists"
      >
        <el-table-column label="订单号" prop="orderSn" min-width="100" />
        <el-table-column label="退货订单" prop="refundSn" min-width="100" />
        <el-table-column label="用户名称" prop="nickname" min-width="100" />
        <el-table-column label="退款金额" prop="refundAmount" min-width="100" />
        <el-table-column label="状态" prop="reviewStatus" min-width="100">
          <template #default="{ row }">
            {{
              row.reviewStatus == 0
                ? "待审核"
                : row.reviewStatus == 1
                ? "通过"
                : "拒绝"
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="数据来源"
          prop="orderTerminalName"
          min-width="100"
        />

        <el-table-column label="创建时间" prop="createTime" min-width="100" />
        <el-table-column label="更新时间" prop="updateTime" min-width="100" />
        <el-table-column label="备注" prop="remark" min-width="100" />
        <el-table-column label="操作" width="120" fixed="right">
          <template #default="{ row }">
            <el-button
              v-perms="['specification:edit']"
              type="primary"
              link
              @click="handleEdit(row)"
              v-if="row.reviewStatus == 0 || row.reviewStatus == 2"
            >
              同意
            </el-button>
            <el-button
              v-perms="['specification:edit']"
              type="primary"
              link
              @click="handleEdit2(row)"
              v-if="row.reviewStatus == 0"
            >
              拒绝
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="flex justify-end mt-4">
        <pagination v-model="pager" @change="getLists" />
      </div>
    </el-card>
  </div>
</template>
<script lang="ts" setup>
import { apirefundlist, apirefundrebates } from "@/api/order/refund.ts";
import { usePaging } from "@/hooks/usePaging";
import { ElMessage, ElMessageBox } from "element-plus";
import feedback from "@/utils/feedback";
// import EditPopup from "./edit.vue";

// const editRef = shallowRef<InstanceType<typeof EditPopup>>();
const showEdit = ref(false);
const queryParams = reactive({
  reviewStatus: 0,
  orderSn: null,
  refundSn: null,
});

const { pager, getLists, resetPage, resetParams } = usePaging({
  fetchFun: apirefundlist,
  params: queryParams,
});
getLists();
const handleEdit = async (data: any) => {
  console.log(data.refundSn, "data");
  apirefundrebates({ refundId: data.id, reviewStatus: 1 }).then((res) => {
    // if (res.code == 200) {
    ElMessage({
      type: "success",
      message: "已同意退款成功",
    });
    resetPage();
    // }
  });
};
const handleEdit2 = async (data: any) => {
  apirefundrebates({ refundId: data.id, reviewStatus: 2 }).then((res) => {
    // if (res.code == 200) {
    ElMessage({
      type: "success",
      message: "已拒绝",
    });
    resetPage();
    // }
  });
};
resetPage();
</script>
